<template>
  <div class="login">
    <router-link
      to="forget"
      class="forget"
    >忘记密码</router-link>
    <div class="logo">
      <img
        src="../include/img/logo.png"
        alt=""
      >
    </div>
    <div class="form">
      <div class="input phone clearfix">
        <span class="fl"></span>
        <input
          class="fl"
          type="number"
          placeholder="填写手机号"
          maxlength="11"
          readonly
          @focus="phoneFocus('phone')"
          v-model="phone"
        >
      </div>
      <div class="input password clearfix">
        <span class="fl"></span>
        <input
          class="fl"
          type="password"
          @focus="phoneFocus('password')"
          placeholder="输入密码"
          v-model="password"
        >
      </div>
    </div>
    <div class="btn" @click="loginBtn">登录</div>
    <van-number-keyboard
      :show="show"
      theme="custom"
      :transition='true'
      close-button-text="完成"
      @input="onInput"
      @delete="onDelete"
      @close="closeClick"
    />
  </div>
</template>

<script>
export default {
  data () {
    return {
      phone: '',
      password: '',
      show: false
    }
  },
  mounted: function () {},
  methods: {
    loginBtn: function () {
      if (this.phone === '') {
        this.$toast.fail({
          message: '请输入手机号'
        })
        return
      }
      if (this.password === '') {
        this.$toast.fail({
          message: '请输入密码'
        })
        return
      }
      this.$router.push({
        path: '../index'
      })
    },
    phoneFocus (e) {
      if (e === 'phone') {
        this.show = true
      } else if (e === 'password') {
        this.show = false
      }
    },
    onInput (key) {
      console.log(key)
      this.phone = (this.phone + key).slice(0, 11)
    },
    onDelete () {
      this.phone = this.phone.slice(0, this.phone.length - 1)
    },
    closeClick () {
      this.show = false
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.login {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: url("./img/back.png") no-repeat center;
  background-size: 100% 100%;
  .btn {
    font-size: 0.34rem;
    color: #313131;
    height: 0.8rem;
    line-height: 0.8rem;
    width: 6.9rem;
    position: absolute;
    left: 50%;
    margin-left: -3.45rem;
    top: 7.26rem;
    text-align: center;
    cursor: pointer;
    background: #fff;
    border-radius: 0.6rem;
  }
  .forget {
    color: #fff;
    font-size: 0.3rem;
    position: absolute;
    right: 0.3rem;
    top: 0.6rem;
  }

  .logo {
    width: 2.14rem;
    position: absolute;
    top: 1.2rem;
    left: 50%;
    margin-left: -1.07rem;
  }

  .form {
    width: 6.9rem;
    position: absolute;
    left: 50%;
    margin-left: -3.45rem;
    top: 4.36rem;
    background-color: #fff;
    border-radius: 0.4rem;
    span {
      width: 1.05rem;
      height: 1.3rem;
    }
    input {
      width: 5rem;
      height: 1.3rem;
      font-size: 0.32rem;
    }
    .phone {
      span {
        background: url("./img/phone_ico.png") no-repeat center;
        background-size: 0.26rem 0.34rem;
      }
    }
    .password {
      span {
        background: url("./img/pass_ico.png") no-repeat center;
        background-size: 0.27rem 0.33rem;
      }
    }
  }
}
</style>
